package cn.edu.lcu.cs.javaprogramming.io;

import lombok.Cleanup;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource;

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

/**
 * properties文件操作演示
 * <p>
 * 2022/5/13 16:53
 *
 * @Author ling
 */
public class PropertiesFileDemo {

    /**
     * 加载属性文件
     *
     * @param filename
     * @throws IOException
     */
    @ParameterizedTest
    @ValueSource(strings = {"/db.properties"})
    void loadProperties(String filename) throws IOException {
        Properties properties = new Properties();
        @Cleanup
        InputStream inputStream = getClass().getResourceAsStream(filename);
        properties.load(inputStream);
        properties.forEach((k, v) -> System.out.println(k + "\t" + v));
    }
}
